home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_Clone.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  7KB  |  320 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_CLONING
  15. VOID
  16. LTP_CloneScreen(struct LayoutHandle *Handle,LONG Width,LONG Height)
  17. {
  18.     struct ColorSpec    *ColourSpec;
  19.     struct ColourRecord    *ColourRecord;
  20.     struct CloneExtra    *Extra;
  21.     LONG                 AllocationSize;
  22.     LONG                 i,j,NumColours;
  23.     UWORD                *Pens;
  24.     struct Screen        *Screen;
  25.     ULONG                 DisplayID;
  26.     UWORD                 EndPen;
  27.  
  28.     ColourSpec        = NULL;
  29.     ColourRecord    = NULL;
  30.     Extra            = Handle->CloneExtra;
  31.     Pens            = Handle->CloneExtra->ScreenPens;
  32.     DisplayID        = GetVPModeID(&Handle->Screen->ViewPort);
  33.     EndPen            = (UWORD)~0;
  34.  
  35.     if(Handle->ExactClone)
  36.         NumColours = Handle->Screen->ViewPort.ColorMap->Count;
  37.     else
  38.     {
  39.         NumColours = Extra->TotalPens;
  40.  
  41.         DisplayID &= ~(HAM | EXTRA_HALFBRITE);
  42.     }
  43.  
  44.     Height += Handle->Screen->BarHeight + 1;
  45.  
  46.     if(Width < Extra->MinWidth)
  47.         Width = Extra->MinWidth;
  48.  
  49.     if(Height < Extra->MinHeight)
  50.         Height = Extra->MinHeight;
  51.  
  52.     if(Handle->SimpleClone)
  53.         Pens = &EndPen;
  54.     else
  55.     {
  56.         if(V39)
  57.         {
  58.             if(!(ColourRecord = (struct ColourRecord *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColourRecord) + sizeof(struct ColourTriplet) * NumColours)))
  59.             {
  60.                 DB(kprintf("no colours\n"));
  61.  
  62.                 return;
  63.             }
  64.             else
  65.             {
  66.                 ColourRecord->NumColours = NumColours;
  67.  
  68.                 if(Handle->ExactClone)
  69.                     GetRGB32(Handle->Screen->ViewPort.ColorMap,0,NumColours,(ULONG *)ColourRecord->Triplets);
  70.                 else
  71.                 {
  72.                     for(i = 0 ; i < NumColours ; i++)
  73.                         GetRGB32(Handle->Screen->ViewPort.ColorMap,Extra->Pens[i],1,(ULONG *)&ColourRecord->Triplets[i]);
  74.                 }
  75.             }
  76.         }
  77.         else
  78.         {
  79.             if(!(ColourSpec = (struct ColorSpec *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColorSpec) * (NumColours + 1))))
  80.             {
  81.                 DB(kprintf("no colours either\n"));
  82.  
  83.                 return;
  84.             }
  85.             else
  86.             {
  87.                 LONG RGB,Which;
  88.  
  89.                 for(i = 0 ; i < NumColours ; i++)
  90.                 {
  91.                     if(Handle->ExactClone)
  92.                         Which = i;
  93.                     else
  94.                         Which = Extra->Pens[i];
  95.  
  96.                     RGB = GetRGB4(Handle->Screen->ViewPort.ColorMap,Which);
  97.  
  98.                     ColourSpec[i].ColorIndex    = i;
  99.                     ColourSpec[i].Red            = (RGB >> 8) & 0xF;
  100.                     ColourSpec[i].Green            = (RGB >> 4) & 0xF;
  101.                     ColourSpec[i].Blue            = (RGB       ) & 0xF;
  102.                 }
  103.  
  104.                 ColourSpec[i].ColorIndex = -1;
  105.             }
  106.         }
  107.  
  108.         if(Handle->ExactClone)
  109.         {
  110.             for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  111.                 Pens[i] = Extra->Pens[i];
  112.         }
  113.         else
  114.         {
  115.             for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  116.             {
  117.                 for(j = 0 ; j < NumColours ; j++)
  118.                 {
  119.                     if(Extra->Pens[j] == Handle->DrawInfo->dri_Pens[i])
  120.                     {
  121.                         Pens[i] = j;
  122.  
  123.                         break;
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.  
  129.         Pens[i] = (UWORD)~0;
  130.     }
  131.  
  132.     DB(kprintf("Calling openscreen\n"));
  133.  
  134.     if(Screen = OpenScreenTags(NULL,
  135.         SA_Width,        Width,
  136.         SA_Height,        Height,
  137.         SA_Overscan,    OSCAN_TEXT,
  138.         SA_AutoScroll,    TRUE,
  139.         SA_DisplayID,    DisplayID,
  140.         SA_Behind,        TRUE,
  141.         SA_Depth,        Handle->SimpleClone ? 2 : Extra->Depth,
  142.         SA_Colors,        ColourSpec,
  143.         SA_Colors32,    ColourRecord,
  144.         SA_Pens,        Pens,
  145.         SA_Font,        Handle->TextAttr,
  146.         SA_Title,        Handle->Screen->DefaultTitle,
  147.         SA_SharePens,    TRUE,
  148.         SA_Interleaved,    TRUE,
  149.  
  150.         Handle->SimpleClone ? TAG_IGNORE : SA_BackFill,        &Handle->BackfillHook,
  151.         Handle->SimpleClone ? TAG_IGNORE : SA_BlockPen,        Pens[SHADOWPEN],
  152.         Handle->SimpleClone ? TAG_IGNORE : SA_DetailPen,    Pens[BACKGROUNDPEN],
  153.     TAG_DONE))
  154.     {
  155.         struct DrawInfo *DrawInfo;
  156.  
  157.         DB(kprintf("getting drawinfo\n"));
  158.  
  159.         if(DrawInfo = GetScreenDrawInfo(Screen))
  160.         {
  161.             APTR VisualInfo;
  162.  
  163.             DB(kprintf("getting visualinfo\n"));
  164.  
  165.             if(VisualInfo = GetVisualInfoA(Screen,NULL))
  166.             {
  167.                 UnlockPubScreen(NULL,Handle->PubScreen);
  168.  
  169.                 FreeScreenDrawInfo(Handle->Screen,Handle->DrawInfo);
  170.  
  171.                 FreeVisualInfo(Handle->VisualInfo);
  172.  
  173.                 Pens = DrawInfo->dri_Pens;
  174.  
  175.                 Handle->PubScreen        = NULL;
  176.                 Handle->Screen            = Screen;
  177.                 Handle->DrawInfo        = DrawInfo;
  178.                 Handle->VisualInfo        = VisualInfo;
  179.                 Handle->TextPen            = Pens[TEXTPEN];
  180.                 Handle->BackgroundPen    = Pens[BACKGROUNDPEN];
  181.                 Handle->ShinePen        = Pens[SHINEPEN];
  182.                 Handle->ShadowPen        = Pens[SHADOWPEN];
  183.                 Handle->AspectX            = DrawInfo->dri_Resolution.X;
  184.                 Handle->AspectY            = DrawInfo->dri_Resolution.Y;
  185.  
  186.                 if(Handle->SimpleClone)
  187.                     Handle->MaxPen = 0;
  188.                 else
  189.                     Handle->MaxPen = Extra->TotalPens - 1;
  190.  
  191.                 Extra->Screen = Screen;
  192.  
  193.                 LTP_Free(Handle,ColourRecord,AllocationSize);
  194.                 LTP_Free(Handle,ColourSpec,AllocationSize);
  195.  
  196.                 DB(kprintf("fertig\n"));
  197.  
  198.                 return;
  199.             }
  200.  
  201.             FreeScreenDrawInfo(Screen,DrawInfo);
  202.         }
  203.  
  204.         CloseScreen(Screen);
  205.     }
  206.  
  207.     LTP_Free(Handle,ColourRecord,AllocationSize);
  208.     LTP_Free(Handle,ColourSpec,AllocationSize);
  209.  
  210.     Handle->Failed = TRUE;
  211.  
  212.     DB(kprintf("fehlschlag\n"));
  213. }
  214.  
  215. BOOL
  216. LTP_PrepareCloning(struct LayoutHandle *Handle)
  217. {
  218.     DB(kprintf("prepare cloning\n"));
  219.  
  220.     if(Handle->CloneExtra)
  221.         return(TRUE);
  222.     else
  223.     {
  224.         struct DimensionInfo DimensionInfo;
  225.  
  226.         DB(kprintf("getting dimensions\n"));
  227.  
  228.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,GetVPModeID(&Handle->Screen->ViewPort)))
  229.         {
  230.             LONG AllocationSize;
  231.  
  232.             DB(kprintf("getting cloneextra\n"));
  233.  
  234.             if(Handle->CloneExtra = (struct CloneExtra *)LTP_Alloc(Handle,AllocationSize = sizeof(struct CloneExtra) + (sizeof(LONG) + sizeof(UWORD)) * Handle->DrawInfo->dri_NumPens + sizeof(UWORD)))
  235.             {
  236.                 LONG     i,j,TotalPens = 0;
  237.                 LONG    *Pens;
  238.                 BOOL     NotFound;
  239.  
  240.                 Handle->CloneExtra->Pens            = (LONG *)(Handle->CloneExtra + 1);
  241.                 Handle->CloneExtra->ScreenPens        = (UWORD *)(&Handle->CloneExtra->Pens[Handle->DrawInfo->dri_NumPens]);
  242.                 Handle->CloneExtra->MinWidth        = DimensionInfo.MinRasterWidth;
  243.                 Handle->CloneExtra->MinHeight        = DimensionInfo.MinRasterHeight;
  244.                 Handle->CloneExtra->MaxWidth        = DimensionInfo.MaxRasterWidth;
  245.                 Handle->CloneExtra->MaxHeight        = DimensionInfo.MaxRasterHeight;
  246.  
  247.                 Handle->CloneExtra->Bounds.Left        = 0;
  248.                 Handle->CloneExtra->Bounds.Top        = 0;
  249.                 Handle->CloneExtra->Bounds.Width    = DimensionInfo.MaxRasterWidth;
  250.                 Handle->CloneExtra->Bounds.Height    = DimensionInfo.MaxRasterHeight;
  251.  
  252.                 Pens = Handle->CloneExtra->Pens;
  253.  
  254.                 if(Handle->ExactClone)
  255.                 {
  256.                     for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  257.                         Pens[i] = Handle->DrawInfo->dri_Pens[i];
  258.  
  259.                     TotalPens = Handle->DrawInfo->dri_NumPens;
  260.  
  261.                     Handle->CloneExtra->Depth = Handle->DrawInfo->dri_Depth;
  262.                 }
  263.                 else
  264.                 {
  265.                     for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  266.                     {
  267.                         for(j = 0,NotFound = TRUE ; NotFound && j < TotalPens ; j++)
  268.                         {
  269.                             if(Pens[j] == Handle->DrawInfo->dri_Pens[i])
  270.                                 NotFound = FALSE;
  271.                         }
  272.  
  273.                         if(NotFound)
  274.                             Pens[TotalPens++] = Handle->DrawInfo->dri_Pens[i];
  275.                     }
  276.  
  277.                     for(i = 0 ; i < DimensionInfo.MaxDepth ; i++)
  278.                     {
  279.                         if(TotalPens <= (1L << i))
  280.                         {
  281.                             Handle->CloneExtra->Depth = i;
  282.  
  283.                             break;
  284.                         }
  285.                     }
  286.                 }
  287.  
  288.                 DB(kprintf("totalpens=%ld depth=%ld\n",TotalPens,Handle->CloneExtra->Depth));
  289.  
  290.                 if((Handle->CloneExtra->TotalPens = TotalPens) && Handle->CloneExtra->Depth)
  291.                 {
  292.                     DB(kprintf("setting up glyphs\n"));
  293.  
  294.                     if(LTP_GlyphSetup(Handle,Handle->InitialTextAttr))
  295.                     {
  296.                         Handle->Failed = Handle->Rescaled = FALSE;
  297.  
  298.                         LTP_ResetGroups(Handle->TopGroup);
  299.  
  300.                         DB(kprintf("fertig\n\n"));
  301.  
  302.                         return(TRUE);
  303.                     }
  304.                 }
  305.                 else
  306.                 {
  307.                     LTP_Free(Handle,Handle->CloneExtra,AllocationSize);
  308.  
  309.                     Handle->CloneExtra = NULL;
  310.                 }
  311.             }
  312.         }
  313.     }
  314.  
  315.     DB(kprintf("fehlschlag\n\n"));
  316.  
  317.     return(FALSE);
  318. }
  319. #endif
  320.